package com.chenxi;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

public class MyLock extends Thread{

    private Lock lock = new ReentrantLock();

    @Override
    public void run(){
        lock.lock();
        for (int i = 0;i<5;i++){
            System.out.println("ThreadName = "+Thread.currentThread().getName() + " " + i);
        }
        lock.unlock();
    }

    public static void main(String[] args) {
        MyLock myLock = new MyLock();
        Thread r = new Thread(myLock);
        Thread r1 = new Thread(myLock);
        Thread r2 = new Thread(myLock);
        r.start();r1.start();r2.start();
    }

}
